XML DOM - Document object

# XML DOM - The Document Object

« Previous
Next Chapter »

The Document object represents the entire XML document.

## The Document object

The Document object is the root of a document tree, and gives us the primary access to the document's data.

Since element nodes, text nodes, comments, processing instructions, etc. cannot exist outside the document, the Document object also contains methods to create these objects. The Node objects have a ownerDocument property which associates them with the Document where they were created.

## Document Object Properties

Property | Description
--- | ---
async | Specifies whether downloading of an XML file should be handled asynchronously or not
childNodes | Returns a NodeList of child nodes for the document
doctype | Returns the Document Type Declaration associated with the document
documentElement | Returns the root node of the document
documentURI | Sets or returns the location of the document
domConfig | Returns the configuration used when normalizeDocument() is invoked
firstChild | Returns the first child node of the document
implementation | Returns the DOMImplementation object that handles this document
inputEncoding | Returns the encoding used for the document (when parsing)
lastChild | Returns the last child node of the document
nodeName | Returns the name of a node (depending on its type)
nodeType | Returns the node type of a node
nodeValue | Sets or returns the value of a node (depending on its type)
strictErrorChecking | Sets or returns whether error-checking is enforced or not
xmlEncoding | Returns the XML encoding of the document
xmlStandalone | Sets or returns whether the document is standalone
xmlVersion | Sets or returns the XML version of the document

## Document Object Methods

Method | Description
--- | ---
adoptNode(sourcenode) | Adopts a node from another document to this document, and returns the adopted node
createAttribute(name) | Creates an attribute node with the specified name, and returns the new Attr object
createAttributeNS(uri,name) | Creates an attribute node with the specified name and namespace, and returns the new Attr object
createCDATASection() | Creates a CDATA section node
createComment() | Creates a comment node
createDocumentFragment() | Creates an empty DocumentFragment object, and returns it
createElement() | Creates an element node
createElementNS() | Creates an element node with a specified namespace
createEntityReference(name) | Creates an EntityReference object, and returns it
createProcessingInstruction(target,data) | Creates a ProcessingInstruction object, and returns it
createTextNode() | Creates a text node
getElementById(id) | Returns the element that has an ID attribute with the given value. If no such element exists, it returns null
getElementsByTagName() | Returns a NodeList of all elements with a specified name
getElementsByTagNameNS() | Returns a NodeList of all elements with a specified name and namespace
importNode(nodetoimport,deep) | Imports a node from another document to this document. This method creates a new copy of the source node. If the deep parameter is set to true, it imports all children of the specified node. If set to false, it imports only the node itself. This method returns the imported node
normalizeDocument() |
renameNode() | Renames an element or attribute node

« Previous
Next Chapter »

### WEB HOSTING

UK Reseller Hosting

### WEB BUILDING

FREE Website BUILDER Free HTML5 Templates

### W3SCHOOLS EXAMS

HTML, CSS, JavaScript, PHP, jQuery, XML, and ASP Certifications

### SHARE THIS PAGE

### Color Picker

### HTML/CSS

HTML Tutorial HTML5 Tutorial CSS Tutorial CSS3 Tutorial Bootstrap Tutorial

### JavaScript

JavaScript Tutorial jQuery Tutorial jQuery Mobile Tutorial AngularJS Tutorial AJAX Tutorial JSON Tutorial

### Graphics

Canvas Tutorial SVG Tutorial Google Maps Tutorial

### Server Side

SQL Tutorial PHP Tutorial ASP Tutorial ASP.NET Tutorial VBScript Tutorial AppML Tutorial

### Web

Web Building Web Statistics Web Certification

### XML

XML Tutorial DTD Tutorial Schema Tutorial XML DOM Tutorial XPath Tutorial XSLT Tutorial XQuery Tutorial XSL-FO Tutorial RSS Tutorial WSDL Tutorial

### HTML/CSS

HTML Tag Reference HTML Event Reference HTML Color Reference CSS 1,2,3 Reference Bootstrap Reference

### JavaScript

JavaScript Reference HTML DOM Reference jQuery Reference jQuery Mobile Reference Google Maps Reference

### Server Side

PHP Reference SQL Reference ASP Reference VBScript Reference Razor Reference ASP.NET Reference

### XML

XML DOM Reference XSLT Reference XSL-FO Reference XPath Reference XQuery Reference Schema Reference RSS Reference SVG Reference

### HTML Charsets

HTML Character Sets HTML ASCII HTML ANSI HTML Windows-1252 HTML ISO-8859-1 HTML Symbols HTML UTF-8

### HTML/CSS

HTML Examples CSS Examples

### Browser Scripting

JavaScript Examples HTML DOM Examples jQuery Examples jQuery Mobile Examples AngularJS Examples AJAX Examples

### Server Scripting

PHP Examples ASP Examples VBScript Examples Razor Examples .NET Examples

### XML Languages

XML Examples DTD Examples XML DOM Examples XSL Examples XSLT Examples XPath Examples XQuery Examples Schema Examples RSS Examples SVG Examples